<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>会员列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="/resource/layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="/resource/css/mylay.css">
		<link rel="stylesheet" href="/resource/css/agent_commission_reward.css">
		<!-- <link rel="stylesheet" href="./layui/css/layui.css" media="all"> -->
	</head>
	<body>
		<!-- 表单元素 -->
		<div class="layui-tab">
			<ul class="layui-tab-title">
				<li class="layui-this">个人佣金奖励</li>
				<li>团队佣金奖励</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show geRenYeJi">
					<div style="padding: 20px; background-color: #F2F2F2;">
						<div class="layui-row layui-col-space15">
							<div class="layui-col-md12">
								<div class="layui-card" style="padding: 10px;">
									<form class="layui-form search">
										<div class="layui-form-item">
											<div class="layui-inline">
												<label class="layui-form-label">统计时间</label>
												<div class="layui-input-inline">
													<input class="layui-input" id="gerenRange" name="gerenRange" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">用户账户</label>
												<div class="layui-input-inline">
													<input class="layui-input" name="username" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">直属上级</label>
												<div class="layui-input-inline">
													<input class="layui-input" name="account" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">发放模式</label>
												<div class="layui-input-inline">
													<select name="sendMode" lay-search="">
														<option value="1">自动</option>
														<option value="2">手动</option>
													</select>
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">发放状态</label>
												<div class="layui-input-inline">
													<select name="sendState" lay-search="">
														<option value="0">未发放</option>
														<option value="1">已发放</option>
														<option value="2">拒绝</option>
													</select>
												</div>
											</div>

											<div class="layui-inline" style="text-align: center;">
												<button type="button" class="layui-btn" id="layui-btn1" data-type="search">搜索</button>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
					<table id="geRenYeJi" lay-filter="personageTable"></table>
					<script type="text/html" id="personageOperation">
						<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="grant">发放</a>
					  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="refused">拒绝</a>
					</script>
				</div>
				<!-- 头部左侧工具栏 -->
				<script type="text/html" id="toolbarDemo">
					<div class="layui-btn-container layui-btn-group">
						<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="calculatePerformance">业绩计算</button>
						<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="calculateCommission">佣金计算</button>
					</div>
				</script>
				<div class="layui-tab-item tuanDuiYeJi">
					<div style="padding: 20px; background-color: #F2F2F2;">
						<div class="layui-row layui-col-space15">
							<div class="layui-col-md12">
								<div class="layui-card" style="padding: 10px;">
									<form class="layui-form search">
										<div class="layui-form-item">
											<div class="layui-inline">
												<label class="layui-form-label">统计时间</label>
												<div class="layui-input-inline">
													<input class="layui-input" id="tuanduiRange" name="tuanduiRange" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">用户账户</label>
												<div class="layui-input-inline">
													<input class="layui-input" name="username2" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">直属上级</label>
												<div class="layui-input-inline">
													<input class="layui-input" name="account2" autocomplete="off">
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">发放模式</label>
												<div class="layui-input-inline">
													<select name="sendMode2" lay-search="">
														<option value="1">自动</option>
														<option value="2">手动</option>
													</select>
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">发放状态</label>
												<div class="layui-input-inline">
													<select name="sendState2" lay-search="">
														<option value="0">未发放</option>
														<option value="1">已发放</option>
														<option value="2">拒绝</option>
													</select>
												</div>
											</div>

											<div class="layui-inline" style="text-align: center;">
												<button type="button" class="layui-btn" id="layui-btn2" data-type="search">搜索</button>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
					<table id="tuanDuiYeJi" lay-filter="teamTable"></table>
					<script type="text/html" id="teamOperation">
						<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="grant">发放</a>
					  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="refused">拒绝</a>
					</script>
				</div>
			</div>
		</div>
		<!-- <script src="./layui/layui.js"></script> -->
		<script src="/resource/layuiadmin/layui/layui.js"></script>
		<script src="/resource/js/manage/init_date.js"></script>
		<script src="/manage/user.js"></script>
		<script>
			//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
			layui.use(['form', 'element', 'table'], function() {
				var $ = layui.$
				var element = layui.element;
				var form = layui.form;
				var table = layui.table;
				var laydate = layui.laydate;

				// 头部左侧工具栏事件
				table.on('toolbar(personageTable)', function(obj){
					switch(obj.event){
						case 'calculatePerformance':
							layer.confirm('确定计算代理业绩？', {
								btn: ['确定','取消'] //按钮
							}, function(){
								$.ajax({
									url: "/manage/useragent/calculatePerformance",
									data: {

									},
									type: "POST",
									dataType: "json",
									timeout: 15000,
									beforeSend: function(){
										layer.load(1);
									},
									success: function(msg){
										var alertStr = (msg == 1) ? '计算完成' : msg;
										layer.msg(alertStr, {time: 2000}, function(){
											if(msg==1){
												layer.closeAll();
												layui.table.reload('geRenYeJi');
												layui.table.reload('tuanDuiYeJi');
											}
										});
									},
									complete: function(){
										layer.closeAll("loading");
									}
								});
							}, function(){
								layer.msg('取消操作', {
									time: 2000, //2s后自动关闭
								});
							});
							break;
						case 'calculateCommission':
							layer.confirm('确定计算代理佣金？', {
								btn: ['确定','取消'] //按钮
							}, function(){
								$.ajax({
									url: "/manage/useragent/calculateCommission",
									data: {

									},
									type: "POST",
									dataType: "json",
									timeout: 15000,
									beforeSend: function(){
										layer.load(1);
									},
									success: function(msg){
										var alertStr = (msg == 1) ? '计算完成' : msg;
										layer.msg(alertStr, {time: 2000}, function(){
											if(msg==1){
												layer.closeAll();
												layui.table.reload('geRenYeJi');
												layui.table.reload('tuanDuiYeJi');
											}
										});
									},
									complete: function(){
										layer.closeAll("loading");
									}
								});
							}, function(){
								layer.msg('取消操作', {
									time: 2000, //2s后自动关闭
								});
							});
							break;
					};
				});

				// 个人业绩奖励设置
				(function() {
					laydate.render({
						elem: '#gerenRange',
						type: 'datetime',
						range: true
					});
					//监听工具条
					table.on('tool(personageTable)', function(obj) {
						var data = obj.data;
						var msg = '您确定要对该笔佣金进行【发放】，发放金额将直接添加到用户账户中？';
						if (obj.event=='refused')
							msg = '拒绝本次发放申请？拒绝后将不再统计本次佣金奖励？';
						layer.confirm(msg, {
							btn: ['确定','取消'] //按钮
						}, function(){
							$.ajax({
								url: "/manage/useragent/rewardSend",
								data: {
									data: data,
									action:obj.event
								},
								type: "POST",
								dataType: "json",
								timeout: 15000,
								beforeSend: function(){
									layer.load(1);
								},
								success: function(msg){
									var alertStr = (msg == 1) ? '操作完成' : "发放失败:"+msg;
									layer.msg(alertStr, {time: 2000}, function(){
										if(msg==1){
											layer.closeAll();
											layui.table.reload('geRenYeJi');
										}
									});
								},
								complete: function(){
									layer.closeAll("loading");
								}
							});
						}, function(){
						});
					});
					table.render({
						elem: '#geRenYeJi',
						title: "个人佣金查询",
						url: '/manage/useragent/agentCommissionReward',
						method: 'get',
						cols: [
							[
								//表头
								{
									field: 'id',
									title: 'ID'
								}, {
									field: 'uid',
									title: '用户ID'
								}, {
									field: 'username',
									title: '用户账户'
								}, {
									field: 'sid',
									title: '直属上级ID'
								}, {
									field: 'cr_date',
									title: '统计时间'
								}, {
									field: 'total_tasks',
									title: '完成任务数'
								}, {
									field: 'total_task_amount',
									title: '完成任务总额'
								}, {
									field: 'discount',
									title: '奖励比例%'
								}, {
									field: 'reward_amount',
									title: '奖励金额'
								}, {
									field: 'performance_period',
									title: '结算周期'
								}, {
									field: 'send_mode',
									title: '发放模式'
								}, {
									field: 'send_state',
									title: '发放状态'
								}, {
									field: 'personageOperation',
									toolbar: '#personageOperation',
									title: '操作'
								}

							]
						],
						cellMinWidth: 100,
						toolbar: '#toolbarDemo',
						defaultToobar: ["filter", 'print', 'exports'],
						totalRow: true,
						page: {
							layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
						},
						skin: 'row' //行边框风格
							,
						even: true //开启隔行背景
					});
					active1 = {
						search: function() {
							//执行重载
							table.reload('geRenYeJi', {
								page: {
									curr: 1 //重新从第 1 页开始
								},
								where: {
									username: $("input[name='username']").val(),
									account: $("input[name='account']").val(),
									sendMode: $("select[name='sendMode'] option:selected").val(),
									sendState: $("select[name='sendState'] option:selected").val(),
									datetime_range: $("input[name='gerenRange']").val(),
									performance_type: 1
								}
							}, 'data');
						}
					};

					$('.geRenYeJi #layui-btn1').on('click', function() {
						var type = $(this).data('type');
						active1[type] ? active1[type].call(this) : '';
					});
				}());

				// 团队业绩奖励设置
				(function() {
					laydate.render({
						elem: '#tuanduiRange',
						type: 'datetime',
						range: true
					});
					//监听工具条
					table.on('tool(teamTable)', function(obj) {
						var data = obj.data;
						var msg = '您确定要对该笔佣金进行【发放】，发放金额将直接添加到用户账户中？';
						if (obj.event=='refused')
							msg = '拒绝本次发放申请？拒绝后将不再统计本次佣金奖励？';
						layer.confirm(msg, {
							btn: ['确定','取消'] //按钮
						}, function(){
							$.ajax({
								url: "/manage/useragent/rewardSend",
								data: {
									data: data,
									action:obj.event
								},
								type: "POST",
								dataType: "json",
								timeout: 15000,
								beforeSend: function(){
									layer.load(1);
								},
								success: function(msg){
									var alertStr = (msg == 1) ? '操作完成' : "发放失败"+msg;
									layer.msg(alertStr, {time: 2000}, function(){
										if(msg==1){
											layer.closeAll();
											layui.table.reload('tuanDuiYeJi');
										}
									});
								},
								complete: function(){
									layer.closeAll("loading");
								}
							});
						}, function(){

						});
					});
					table.render({
						elem: '#tuanDuiYeJi',
						title: "团队佣金查询",
						url: '/manage/useragent/agentCommissionReward?performance_type=2',
						method: 'get',
						cols: [
							[
								//表头
								{
									field: 'id',
									title: 'ID'
								}, {
									field: 'uid',
									title: '用户ID'
								}, {
									field: 'username',
									title: '用户账户'
								}, {
									field: 'sid',
									title: '上级UID'
								}, {
									field: 'cr_date',
									title: '统计时间'
								}, {
									field: 'total_tasks',
									title: '完成任务数'
								}, {
									field: 'total_task_amount',
									title: '团队业绩奖励金额'
								}, {
									field: 'amountLimit',
									title:'团队业绩级差奖励金额'
								},{
									field: 'reward_amount',
									title: '发放总额'
								}, {
									field: 'performance_period',
									title: '结算周期'
								}, {
									field: 'send_mode',
									title: '发放模式'
								}, {
									field: 'send_state',
									title: '发放状态'
								}, {
									field: 'teamOperation',
									toolbar: '#teamOperation',
									title: '操作'
								}
							]
						],
						cellMinWidth: 100,
						toolbar: '#toolbarDemo',
						defaultToobar: ["filter", 'print', 'exports'],
						totalRow: true,
						page: {
							layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
						},
						skin: 'row' //行边框风格
							,
						even: true //开启隔行背景
					});
					active2 = {
						search: function() {
							//执行重载
							table.reload('tuanDuiYeJi', {
								page: {
									curr: 1 //重新从第 1 页开始
								},
								where: {
									username: $("input[name='username2']").val(),
									account: $("input[name='account2']").val(),
									sendMode: $("select[name='sendMode2'] option:selected").val(),
									sendState: $("select[name='sendState2'] option:selected").val(),
									datetime_range: $("input[name='tuanduiRange']").val()
								}
							}, 'data');
						}
					};

					$('.tuanDuiYeJi #layui-btn2').on('click', function() {
						var type = $(this).data('type');
						active2[type] ? active2[type].call(this) : '';
					});


				}())




			});
		</script>
	</body>
</html>
